![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
node_extra_ca_certs_mozilla_bundle
Advanced tools
If you are trying to connect to a secure website via nodejs. Although, the site may work in the browser, you may run into errors such as
If you are trying to connect to a secure website via nodejs. Although, the site may work in the browser, you may run into errors such as
UNABLE_TO_VERIFY_LEAF_SIGNATURE
Unable to verify the first certificate
It may be due to a couple of reasons. The Root CA certificate is missing in nodejs Or the site does not correctly install the intermediate certificates.
Typically you encounter these at the last minute, and usually, the server is not in your control; hence you cannot modify the certificate installation, and it is challenging to change code at that time.
When set, the well known "root" CAs (like VeriSign) will be extended with the extra certificates in file. The file should consist of one or more trusted certificates in PEM format.
NOTE: This environment variable is ignored when node runs as setuid root or has Linux file capabilities set.
However, it is cumbersome to create the PEM file for missing certificates manually and it can be a security issue if untrusted certificates are accidentally included.
It generates three different bundles that can be used based on your needs:
ca_intermediate_bundle.pem
ca_root_bundle.pem
ca_intermediate_root_bundle.pem
You can use any of the above bundles with NODE_EXTRA_CA_CERTS.
npm install --save node_extra_ca_certs_mozilla_bundle
During the installation of the module, it downloads the latest certificates from the Mozilla database and builds the PEM file in node_modules/node_extra_ca_certs_mozilla_bundle/ca_bundle
folder.
You can launch your script while using the above certificates using:
NODE_EXTRA_CA_CERTS=node_modules/node_extra_ca_certs_mozilla_bundle/ca_bundle/ca_intermediate_root_bundle.pem node your_script.js
for Windows use:
npx cross-env NODE_EXTRA_CA_CERTS=node_modules/node_extra_ca_certs_mozilla_bundle/ca_bundle/ca_intermediate_root_bundle.pem node your_script.js
This is useful when you want to run as root or listen on privilege port like 80. Since in those situations the above environment variable does not work.
const fs = require('fs');
const https = require('https');
https.globalAgent.options.ca = fs.readFileSync('node_modules/node_extra_ca_certs_mozilla_bundle/ca_bundle/ca_intermediate_root_bundle.pem');
If you want to include your custom certificate and still want to connect to other SSL endpoints, you can concat the custom certificate with the generated bundle and use it.
const fs = require('fs');
const https = require('https');
https.globalAgent.options.ca = yourCertificatePEMcontent + fs.readFileSync('node_modules/node_extra_ca_certs_mozilla_bundle/ca_bundle/ca_intermediate_root_bundle.pem');
FAQs
If you are trying to connect to a secure website via nodejs. Although, the site may work in the browser, you may run into errors such as
We found that node_extra_ca_certs_mozilla_bundle demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.